#pragma once
#include "MovableObject.h"
#include "Frustum.h"
class RenderTarget;

class Camera : public MovableObject
{
private:
	friend class Scene;
	Camera(const std::string& name, Scene* owner);
	~Camera();

public:
	inline const Vector3& getPosition() const { return mPosition; }
	inline void setPosition(const Vector3& v) { mPosition = v; NeedUpdate(); }
	
	inline const Rotator& getRotation() const { return mRotation; }
	inline void setRotation(const Rotator& v) { mRotation = v; NeedUpdate(); }
	
	float getFovY() const { return mFovY; }
	void setFovY(float v) { mFovY = v; NeedUpdate(); }

	float getAspect() const { return mAspect; }
	void setAspect(float v) { mAspect = v; NeedUpdate(); }

	const Matrix& getViewMatrix() const { return mViewMatrix; }
	const Matrix& getProjectionMatrix() const { return mProjectionMatrix; }

	virtual const char* getMovableType() const { return "Camera"; };

	void Render(RenderTarget* renderTarget);
	void NeedUpdate();
	void Update();

	void Move(const Vector3& move);
	void Move(float x, float y, float z) { Move(Vector3(x, y, z)); }
	void Rotate(int x, int y, int z);

	inline bool Visible(const BoxCenterAndExtent& box) { return mFrustum.Visible(box); }

private:
	float mFovY;
	float mAspect;
	float mNearDistance;
	float mFarDistance;
	Vector3 mPosition;
	Rotator mRotation;
	bool mNeedUpdate;
	Frustum mFrustum;
	Matrix mViewMatrix;
	Matrix mProjectionMatrix;
};
